/*
package com.pie4cloud.pie.job.api.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.DefaultResponse;
import org.springframework.cloud.client.loadbalancer.EmptyResponse;
import org.springframework.cloud.client.loadbalancer.Request;
import org.springframework.cloud.client.loadbalancer.Response;
import org.springframework.cloud.loadbalancer.core.ReactorServiceInstanceLoadBalancer;
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Random;

public class CustomRandomLoadBalancerClient implements ReactorServiceInstanceLoadBalancer {

	// 服务列表
	private ObjectProvider<ServiceInstanceListSupplier> serviceInstanceListSupplierProvider;

	public CustomRandomLoadBalancerClient(ObjectProvider<ServiceInstanceListSupplier> serviceInstanceListSupplierProvider) {
		this.serviceInstanceListSupplierProvider = serviceInstanceListSupplierProvider;
	}

	@Override
	public Mono<Response<ServiceInstance>> choose(Request request) {
		serviceInstanceListSupplierProvider=new ObjectProvider<ServiceInstanceListSupplier>() {
			@Override
			public ServiceInstanceListSupplier getObject(Object... objects) throws BeansException {
				return null;
			}

			@Override
			public ServiceInstanceListSupplier getIfAvailable() throws BeansException {
				return null;
			}

			@Override
			public ServiceInstanceListSupplier getIfUnique() throws BeansException {
				return null;
			}

			@Override
			public ServiceInstanceListSupplier getObject() throws BeansException {
				return null;
			}
		};
		ServiceInstanceListSupplier supplier = serviceInstanceListSupplierProvider.getIfAvailable();
		return supplier.get().next().map(this::getInstanceResponse);
	}
	*/
/**
	 * 使用随机数获取服务
	 * @param instances
	 * @return
	 *//*

	private Response<ServiceInstance> getInstanceResponse(
			List<ServiceInstance> instances) {
		ServiceInstance serviceInstance=new DefaultServiceInstance(null,"pie-dmz","127.0.0.1",8858,true);
		instances.add(serviceInstance);
		System.out.println("进来了");
		if (instances.isEmpty()) {
			return new EmptyResponse();
		}

		System.out.println("进行随机选取服务");
		// 随机算法
		int size = instances.size();
		Random random = new Random();
		ServiceInstance instance = instances.get(random.nextInt(size));

		return new DefaultResponse(instance);
	}
}*/
